package com.zenithmind.version.pojo.domain;

import com.baomidou.mybatisplus.annotation.TableName;
import com.zenithmind.common.base.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 提交作者信息实体类 - 遵循单一职责原则，专门处理提交作者相关信息
 * 
 * @author ZenithMind Team
 * @since 2025-01-09
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("version_commit_author")
@Schema(description = "提交作者信息实体")
public class CommitAuthor extends BaseEntity {

    /**
     * 提交ID
     */
    @Schema(description = "提交ID")
    private String commitId;

    /**
     * 作者名称
     */
    @Schema(description = "作者名称")
    private String authorName;

    /**
     * 作者邮箱
     */
    @Schema(description = "作者邮箱")
    private String authorEmail;

    /**
     * 提交者名称
     */
    @Schema(description = "提交者名称")
    private String committerName;

    /**
     * 提交者邮箱
     */
    @Schema(description = "提交者邮箱")
    private String committerEmail;

    /**
     * 是否已验证（0-否，1-是）
     */
    @Schema(description = "是否已验证（0-否，1-是）")
    private Integer isVerified;

    /**
     * 验证签名
     */
    @Schema(description = "验证签名")
    private String signature;

    /**
     * 检查作者是否已验证
     * 
     * @return 是否已验证
     */
    public boolean isAuthorVerified() {
        return Integer.valueOf(1).equals(this.isVerified);
    }
    
    /**
     * 检查作者和提交者是否为同一人
     * 
     * @return 是否为同一人
     */
    public boolean isSameAuthorAndCommitter() {
        if (authorEmail == null || committerEmail == null) {
            return false;
        }
        return authorEmail.equals(committerEmail);
    }
    
    /**
     * 获取显示名称（优先使用作者名称）
     * 
     * @return 显示名称
     */
    public String getDisplayName() {
        if (authorName != null && !authorName.trim().isEmpty()) {
            return authorName;
        }
        if (authorEmail != null && !authorEmail.trim().isEmpty()) {
            return authorEmail;
        }
        return "Unknown Author";
    }
    
    /**
     * 验证邮箱格式
     * 
     * @return 是否所有邮箱格式都正确
     */
    public boolean isValidEmails() {
        boolean authorEmailValid = authorEmail == null || authorEmail.contains("@");
        boolean committerEmailValid = committerEmail == null || committerEmail.contains("@");
        return authorEmailValid && committerEmailValid;
    }
}
